<!DOCTYPE html>
<html><head>
    <meta charset="UTF-8">
    <title>Login</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f5f5f5;
            padding: 50px;
        }
        .login-container {
            width: 300px;
            margin: 0 auto;
            background-color: #ffffff;
            padding: 20px;
            border-radius: 5px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
        }
        .login-container h2 {
            text-align: center;
            color: #5b7083;
            margin-bottom: 20px;
        }
        .form-group {
            margin-bottom: 15px;
        }
        .form-group label {
            display: block;
            font-weight: bold;
            color: #5b7083;
            margin-bottom: 5px;
        }
        .form-group input {
            width: 100%;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 3px;
            font-size: 14px;
        }
        .form-group input[type="submit"] {
            background-color: #007BFF;
            color: #fff;
            cursor: pointer;
        }
        .form-group input[type="submit"]:hover {
            background-color: #0056b3;
        }
    </style>
    <script src="./vue3.js"></script>
    <script src="./axios.js"></script>
</head>
<body>
<div class="login-container">
    <div id="app">
        <h2>登录</h2>
        <form action="login" method="post">
            <div class="form-group">
                <label for="email">Email:</label>
                <input type="email" v-model="loginUser.email" id="email" name="email" required="">
            </div>
            <div class="form-group">
                <label for="password">Password:</label>
                <input type="password" v-model="loginUser.password" id="password" name="password" required="">
            </div>
            <div class="form-group">
                <input type="button" value="Login" @click="login">
            </div>
        </form>
    </div>
    <script>
        const {createApp} = Vue
        createApp({
            data(){
                return{
                    loginUser:{
                        email:'',
                        password:''
                    }
                }
            },
            methods:{
                login(){
                    // console.log(this.loginUser)
                    axios.get(`http://127.0.0.1:8088/user/login?email=${this.loginUser.email}&password=${this.loginUser.password}`).then(res => {
                        if(res.data.success){
                            alert('登录成功')
                            let loginUser = res.data.data
                            var jsonString = JSON.stringify(loginUser);
                            sessionStorage.setItem('loginUser', jsonString);
                            sessionStorage.setItem('token',loginUser.token)
                            location.href="index.html"
                        }else{
                            alert(res.data.message)
                        }
                    })
                }
            },
            created(){

            }
        }).mount('#app')
    </script>
</div>


</body></html>